﻿using System.Text;

namespace TestWizard
{
    public class CreateUserContext
    {
        public string UserName { get; set; }
        public string FullName { get; set; }
        public string Description { get; set; }

        public bool ShowAdvancedPasswordOptions { get; set; }

        public bool UserMustChangePassword { get; set; }
        public bool UserCannotChangePassword { get; set; }
        public bool PasswordNeverExpires { get; set; }

        public string AdvancedOptions
        {
            get
            {
                if (!ShowAdvancedPasswordOptions)
                    return "(not set)";

                StringBuilder builder = new StringBuilder();
                if (UserMustChangePassword)
                    StringBuilderExtensions.AppendDelim(builder, "User must change password", "; ");
                if (UserCannotChangePassword)
                    StringBuilderExtensions.AppendDelim(builder, "User cannot change password", "; ");
                if (PasswordNeverExpires)
                    StringBuilderExtensions.AppendDelim(builder, "Password never expires", "; ");

                return builder.ToString();
            }
        }
    }

    // If I'd targeted C# 3.0, this could be real extension methods.
    static class StringBuilderExtensions
    {
        public static void AppendDelim(StringBuilder builder, string text, string delim = ", ")
        {
            if (builder.Length != 0)
                builder.Append(delim);
            builder.Append(text);
        }
    }
}